//
//  ShopDetailHeaderView.m
//  FreeTrip
//
//  Created by 352324497@qq.com on 15/11/25.
//  Copyright © 2015年 邓芮. All rights reserved.
//

#import "ShopDetailHeaderView.h"

@implementation ShopDetailHeaderView

-(instancetype)initWithReuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithReuseIdentifier:reuseIdentifier];
    if (self)
    {
        CGFloat height = KScreenWidth / 680 * 408;
        self.iconImageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, KScreenWidth, height)];
        [self.contentView addSubview:_iconImageView];
        
        UIView *coverView = [[UIView alloc]initWithFrame:self.iconImageView.frame];
        coverView.backgroundColor = [UIColor blackColor];
        coverView.alpha = 0.3;
        [self.contentView addSubview:coverView];
        
        CGFloat width = KScreenWidth - 20 * KScreenWidth / 375;
        self.nameLabel = [[UILabel alloc]initWithFrame:CGRectMake(10 * KScreenWidth / 375, 10 * KScreenWidth / 375, width, 30 * KScreenWidth / 375)];
        self.nameLabel.textColor = [UIColor whiteColor];
        self.nameLabel.numberOfLines = 0;
        self.nameLabel.font = [UIFont systemFontOfSize:20 * KScreenWidth / 375];
        [self.contentView addSubview:_nameLabel];
    }
    return self;
}

-(void)setModel:(ShopDetailHeaderModel *)model
{
//    NSLog(@"model --- %@", model.name);
    CGFloat width = KScreenWidth - 20 * KScreenWidth / 375;
    CGFloat height = KScreenWidth / 680 * 408;
    _model = model;
    [self.iconImageView sd_setImageWithURL:[NSURL URLWithString:model.image_url] placeholderImage:[UIImage imageNamed:@"placeholder"]];
    self.nameLabel.text = [NSString stringWithFormat:@"%@ (%@)", model.name, model.price];
    
    CGRect bounds = [self.nameLabel.text boundingRectWithSize:CGSizeMake(width, 100 * KScreenWidth / 375) options:(NSStringDrawingUsesLineFragmentOrigin) attributes:[NSDictionary dictionaryWithObject:[UIFont systemFontOfSize:20 * KScreenWidth / 375] forKey:NSFontAttributeName] context:nil];
    self.nameLabel.frame = CGRectMake(10 * KScreenWidth / 375, height - 10 * KScreenWidth / 375 - bounds.size.height, width, bounds.size.height);
}
+(CGFloat)heightForHeader
{
    return KScreenWidth / 680 * 408;
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
